﻿using System;
using System.Collections.Generic;
using TallyBook.DAL.Repository;
using TallyBook.DAL.Repository.Imp;

namespace TallyBook.BLL.Service.Imp
{
    public class OutlayService : IOutlayService<Outlay>
    {
        private readonly IRepository<Outlay> _repository = RepositoryFactory<Outlay>.Instance.CreatRepository();


        public Outlay Get(long id)
        {
            return _repository.Get(id);
        }

        public List<Outlay> GetAll()
        {
            return _repository.GetAll();
        }

        public int Insert(long accounttypeid, long outlaytypeid, long outlayid, decimal money,
            string comment, DateTime time)
        {
            var outlaies = new Outlay
            {
                AccountTypeId = accounttypeid,
                OutLayTypeId = outlaytypeid,
                Id = outlayid,
                Money = money,
                Comment = comment,
                CreateTime = time
            };
            return _repository.Insert(outlaies);
        }

        public int Update(long accounttypeid, long outlaytypeid, long outlayid, decimal money, string comment,
            DateTime time)
        {
            var outlaies = new Outlay
            {
                AccountTypeId = accounttypeid,
                OutLayTypeId = outlaytypeid,
                Id = outlayid,
                Money = money,
                Comment = comment,
                CreateTime = time
            };
            return _repository.Update(outlaies);
        }

        public int Delete(long entity)
        {
            var outlay = new Outlay
            {
                Id = entity
            };
            return _repository.Delete(outlay);
        }

        public List<OutLayType> GetName()
        {
            OutlayRepository outlayTypeRepository = RepositoryFactory<OutLayType>.Instance.OutLayTypeRepository();
            return outlayTypeRepository.GetName();
        }

        public List<Outlay> GetDim(long incomesource)
        {
            OutlayRepository outlayTypeRepository = RepositoryFactory<Outlay>.Instance.OutLayTypeRepository();
            return outlayTypeRepository.GetDim(incomesource);
        }

        public List<Outlay> GetDim(decimal incomesource)
        {
            OutlayRepository outlayTypeRepository = RepositoryFactory<Outlay>.Instance.OutLayTypeRepository();
            return outlayTypeRepository.GetDim(incomesource);
        }
    }
}